package cn.zhiquxing.exception;

import cn.zhiquxing.domain.ProcessContext;
import cn.zhiquxing.enums.RespStatusEnum;

import java.util.Objects;

/**
 * 责任链上下文异常
 * @author jeff
 */
public class ProcessException extends RuntimeException {

    private ProcessContext processContext;

    public ProcessException(ProcessContext processContext) {
        super();
        this.processContext = processContext;
    }

    public ProcessException(ProcessContext processContext, Throwable cause) {
        super(cause);
        this.processContext = processContext;
    }

    @Override
    public String getMessage() {
        if (Objects.nonNull(this.processContext)) {
            return this.processContext.getResponse().getMsg();
        }
        return RespStatusEnum.CONTEXT_IS_NULL.getMsg();
    }

    public ProcessContext getProcessContext() {
        return processContext;
    }
}
